 <%-- 客户管理 --%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<script type="text/javascript" src="jquery-easyui-1.4.3/jquery.edatagrid.js"></script>
<script type="text/javascript" src="js/uploadPreview.js"></script>
<script type="text/javascript" src="js/ajaxfileupload.js"></script>
<script type="text/javascript" src="backadmin/ckeditor/ckeditor.js"></script>
<div class="easyui-layout" fit="true" style="height:100%;">
	<div data-options="region:'north'"  >
	    <input name="codition" id="ss" class="easyui-searchbox"
			searcher="searchskin" prompt="请输入皮肤编号"
			style="width:130px;vertical-align:middle;"></input>
    </div>
	<%-- 表格数据区域 --%>
	<div region="center" border="false">
		<table id="skintable" ></table>
	</div>
</div>
<%--用于修改图片的对话框 --%>
<div id="skinDialog" class="easyui-dialog" title="用户头像" style="width: 650px; height: 500px;"  
                data-options="iconCls:'icon-edit',modal:true,collapsible:false,minimizable:false,maximizable:false,resizable:false,closed:true,closable:false">  
    <div style="margin-left: 5px;margin-right: 5px;margin-top: 5px;">           
		<form name="skinform" id="skinform">
			<input type="hidden" id="sid" name="sid" value=""/>
	        <table style="margin-top: 20px;margin-left:20px;margin-right:20px;vertical-align:middle;" width="80%" border="0" cellpadding="0" cellspacing="1">  
	            <tr>  
	                <td>  
	              		<div id="skindiv"><img id="skin" width="530" height="360" /></div>
	                </td>  
	            </tr> 
	            <tr>  
	                <td><input type="file" id="newskin" name="newskin" /></td>
	            </tr>
	        </table>  
        </form>
        <div style="text-align:right;margin-right:30px;">  
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="updateskin()">修改</a>  
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="yhj_cancel('skinDialog')">取消</a>  
        </div>                  
    </div>          
</div>  


<%--用于查看详情的对话框 --%>
<div id="detailDialog" class="easyui-dialog" title="商品详情" style="width: 650px; height: 500px;"  
                data-options="iconCls:'icon-edit',modal:true,collapsible:false,minimizable:false,maximizable:true,resizable:false,closed:true,closable:false">  
    <div style="margin-left: 5px;margin-right: 5px;margin-top: 5px;">           
		<form name="detailform" id="detailform">
			<input type="hidden" id="detailpid" name="detailpid" value=""/>
			<textarea class="ckeditor" name="detail"></textarea>
        </form>
        <div style="text-align:right;margin-right:30px;">  
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="updateDetail()">修改</a>  
            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="yhj_cancel('detailDialog')">取消</a>  
        </div>                  
    </div>          
</div>  

<script type="text/javascript">
	//上传更改头像的方法
	function updateskin(){
		if($("#newskin").val()==""){
			alert("不能插入空图片");
			return ;
		}
		$.ajaxFileUpload({
			url:"backadmin/file.action",//这个action主要用来接收上传的文件
			secureuri:false,//上传的时候是否使用安全协议https而不用http
			type:"POST",
			dataType:"JSON",
			fileElementId:"newskin",//上传文件域的id
			data:{op:'userskin',sid:$("#sid").val(),addrDir:'/images/background'},
			success:function(data){
				if(data!=""){
					$("#skinDialog").window("close");
					//$('#UimageDialog').datagrid('load'); 
					searchskin("","");
					showinfobox(1,"","修改成功...");
				}else{
					//失败了
					showinfobox(1,"","修改失败...");
				}
			}
		});
	}
	
	
	//查询商品的方法
	function searchskin(value,name){
		$("#skintable").edatagrid({
			url:"backadmin/skin.action?op=findallskin",
		    saveUrl: "backadmin/skin.action?op=addskin",
		    updateUrl: "backadmin/skin.action?op=updateskin",
		    idField:"sid",
			pagination:true,
			pageNumber:1,
			pageSize:10,
			pageList:[10,20,30,40,50],
			fit:true,
			rownumbers:true,
			sortName:"sid",
			title:"皮肤管理表",
			sortOrder:"desc",
			fitColumns:true,
			singleSelect:true,
			queryParams:{
				searchOptions:value,
				seacherType:name
			},
			columns:[[
				{field:"sid",title:"皮肤编号",width:100,align:"center"},
				{field:"simage",title:"皮肤背景",width:100,align:"center",
					formatter:function(value,rec){
	        			return '<img class="editCls1" src="images/background/'+value+'" width="160" height="90" href="javascript:void(0)" onclick="changebackimg(\''+rec.sid+'\',\''+value+'\')"/>';
					}
				},
				{field:"scolor",title:"皮肤主色调",width:100,align:"center",editor:'text'},
				{field:"sstatus",title:"皮肤状态",width:100,align:"center",editor:'text',
					formatter:function(value){
						if(value==0){
							return "<font color='red'>已禁用\\0</font>";
						}else{
							return "<font color='green'>已开启\\1</font>";
						}
					}
				}
			]],
			onLoadSuccess:function(data){
				$("#skintable").edatagrid("fitColumns");//修复不对齐的bug
			},
			onAfterEdit:function(data){//编辑后修改linkbutton
				//alert("编辑后");
			},
			toolbar:[
			         {
			        	 iconCls:'icon-add',
			        	 text:"添加",
			        	 handler:function(){
			        		 $("#skintable").edatagrid('addRow');
			        	 }
			         },{
			        	 iconCls:'icon-save',
			        	 text:"保存",
			        	 handler:function(){
			        		 $("#skintable").edatagrid('saveRow');//完成添加或更新
			        	 }
			         },{
			        	 iconCls:'icon-undo',
			        	 text:"取消编辑",
			        	 handler:function(){
			        		 $("#skintable").edatagrid('cancelRow');
			        	 }
			  		  }
			  ]
		});
	}
	
	$(function(){
		searchskin(null,null);
		
		new uploadPreview({ UpBtn: "newskin", DivShow: "skindiv", ImgShow: "skin" });
	});
	
	function changebackimg(sid,skin){
		if(skin!="undefinde"||skin!=""){
			$("#skin").attr("src","images/mixedPicData/"+skin);
		}else{
			$("#skin").attr("src","images/yhj_upload.png");
		}
		$("#sid").val(sid);
		new uploadPreview({ UpBtn: "newskin", DivShow: "skindiv", ImgShow: "skin" });
		$("#skinDialog").window("open");
	}
	function yhj_cancel(name){
		$("#skin").removeAttr("src");
		$("#newskin").val("");
		$("#skinDialog").window("close");
	}
	
</script>	     